package com.shsubway.utils;

import java.math.BigDecimal;

/**
 * Created by Hu on 2016/10/31.
 */

public class BigDisMailUtils {

    public static BigDecimal turn(Object val, int i) {
        BigDecimal bd = new BigDecimal(val.toString());
        bd = bd.setScale(i, BigDecimal.ROUND_HALF_UP);//BigDecimal.ROUND_HALF_UP 是4舍5入
        return bd;
    }

    public static String turnTrim(Object val) {
        return noTrim(turn(val.toString(), 2));
    }

    public static String turnTrim(Object val,int i) {
        return noTrim(turn(val.toString(), i));
    }

    public static String noTrim(BigDecimal s) {
        String ss = s.toString();
        String sss = null;
        if (ss.indexOf(".") > 0) {
            //正则表达
            sss = ss.replaceAll("0+?$", "");//去掉后面无用的零
            sss = ss.replaceAll("[.]$", "");//如小数点后面全是零则去掉小数点
        }
        return sss;
    }
}
